<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2021/9/7
 * Time: 14:43
 */
namespace app\admin\controller;


use app\BaseController;
use app\middleware\AdminCheck;
use think\facade\Db;

class ContentSetting extends BaseController{

    protected $middleware = [
        AdminCheck::class => ['except' 	=> [''] ]
    ];


    /**
    *  @SWG\Get(
    *    path="/admin/contentSetting/getList",
    *    tags={"后台系统配置相关"},
    *    summary="系统配置列表",
    *    @SWG\Parameter(
    *    in="query",
    *    required=false,
    *    name="id",
    *    type="integer",
    *    description="不需要参数"),
    *  @SWG\Response(response="200",description="ok")
    *  )
    */
    /**
     * 系统配置列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
        public function getList(){

        $list=Db::name('system_content_setting')
            ->field('id,name,type,value')
            ->select();
        return success('系统配置列表',$list);
    }



    /**
    *  @SWG\Get(
    *    path="/admin/contentSetting/detail",
    *    tags={"后台系统配置相关"},
    *    summary="获取系统内容详情",
    *    @SWG\Parameter(
    *    in="query",
    *    required=true,
    *    name="id",
    *    type="integer",
    *    description="系统配置的id"),
    *  @SWG\Response(response="200",description="ok")
    *  )
    */
    /**
     * 获取系统内容详情
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function detail(){
        validateParam('id','id');
        $id=input('id');
        $detail=Db::name('system_content_setting')
            ->field('id,name,type,value')
            ->where('id','=',$id)
            ->find();
        return success('系统配置内容详情',$detail);
    }


    /**
    *   @SWG\Post(
    *     path="/admin/contentSetting/edit",
    *     tags={"后台系统配置相关"},
    *     summary="编辑系统配置",
    *     consumes={"application/json"},
    *     produces={"application/json"},
    *     @SWG\Parameter(
    *      in="query",
    *      required=true,
    *      name="id",
    *      type="string",
    *      description="配置的id"),
    *     @SWG\Parameter(
    *      in="query",
    *      required=true,
    *      name="value",
    *      type="string",
    *      description="配置的内容"),
    *     @SWG\Response(response="200",description="ok")
    *  )
    */
    /**
     * 编辑系统配置
     * @throws \think\db\exception\DbException
     */
    public function edit(){
        validateParam('id,value','id,value');
        $value=htmlspecialchars_decode(input('value'));
        Db::name('system_content_setting')
            ->where(['id'=>input('id')])
            ->update(['value'=>$value]);
        return success('编辑系统配置成功');
    }
}